package com.app.micaihu.custom.view.dataview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.bean.news.VideoChannel;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.image.LoadImageUtils;

/**
 * 视频栏目icon的自定义控件
 * Created by linkai on 2016/9/7.
 */
public class VideoChannelView extends LinearLayout {

    String key;

    private boolean isShow;//红点是否显示

    public VideoChannelView(Context context) {
        super(context);
        inflate(context, R.layout.view_videochanel, this);
    }

    public VideoChannelView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(context, R.layout.view_videochanel, this);
    }

    /**
     * 初始化数据
     *
     * @param videoChannel
     */
    public void setData(VideoChannel videoChannel) {
        if (videoChannel == null) {
            setVisibility(View.GONE);
            return;
        }
//        TextView title = (TextView) findViewById(android.R.id.text1);
//        title.setText(videoChannel.getTitle());
//        if(videoChannel.getIsUpdate()
//                && AppConfigManager.getInstance().readConfig(videoChannel.getIdentification(),true)){
//            findViewById(android.R.id.text2).setVisibility(View.VISIBLE);
//            key = videoChannel.getIdentification();
//            isShow = true;
//        }else{
//            findViewById(android.R.id.text2).setVisibility(View.GONE);
//            isShow = false;
//        }
//        setTag(videoChannel);


        CustomImageView img = (CustomImageView) findViewById(android.R.id.icon);
        if (img != null) {
            LoadImageUtils.getInstance().loadImage(img, videoChannel.getIcon());
            img.getHierarchy().setOverlayImage(null);
        }
        TextView title = (TextView) findViewById(android.R.id.text1);
        title.setText(videoChannel.getTitle());
        setTag(videoChannel);
    }

    /**
     * 隐藏红点
     */
    public void hideRedDot() {
//        if(isShow){
//            findViewById(android.R.id.text2).setVisibility(View.GONE);
//            AppConfigManager.getInstance().writeConfig(key, false);
//            isShow = false;
//        }
    }
}
